package com.tmall.testgen.common.socket.syn;

import java.util.ArrayList;
import java.util.List;

/**
 * @author haojia
 * @date 2014-07-04
 */
public class SynCallBackCenter {

	private List<SynCallBack> callBacks=new ArrayList<SynCallBack>();
	
	private static SynCallBackCenter instance=new SynCallBackCenter();
	
	public static SynCallBackCenter getInstance(){
		return instance;
	}
	
	public void addSynCallBack(SynCallBack synCallBack){
		callBacks.add(synCallBack);
	}
	
	public void handleReceive(SynObject synObj){
		List<SynCallBack> toRemove=new ArrayList<SynCallBack>();
		
		for(SynCallBack callBack:callBacks){
			if(callBack.callBack(synObj))
				toRemove.add(callBack);
		}
		callBacks.removeAll(toRemove);
	}
}
